package response

import (
	"github.com/asaskevich/govalidator"
	"time"
)

type TokenInfo struct {
	Token string `json:"token" example:"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1NTQ4ODgwMzQsIm5iZiI6MTU1NDg4NDQzNCwidWlkIjo1ODgzfQ.w9FQghGEx7AQ_eQkmZGcjiMq8oNheFHkiQeTnKZyETA"`
	Uid   int64  `json:"uid" example:"58"`
}

type UserScoreInfo struct {
	UserInfo  UserInfo     `json:"user_info"`
	ScoreInfo AllScoreInfo `json:"score_info"`
}

type UserInfo struct {
	Name       string  `json:"name" example:"鲜天麒"`
	PicUrl     string  `json:"pic_url" example:"https://test-jingshi-pic.oss-cn-beijing.aliyuncs.com/avatar/defalut-male.png"`
	NickName   string  `json:"nick_name" example:"鲜天麒"`
	Phone      string  `json:"phone" example:"18810566938"`
	Gender     string  `json:"gender" example:"男"`
	Birth      string  `json:"birth" example:"2010-10-20"`
	Height     float32 `json:"height" example:"122.00"`
	Weight     float32 `json:"weight" example:"33.90"`
	StudentId  string  `json:"student_id" example:"2018120118122213"`
	Grade      int     `json:"grade" example:"1"` //年级号,如1，中文还需要自己转换
	Class      int     `json:"class" example:"1"` //班级号,如1，中文还需要自己转换
	SchoolName string  `json:"school_name" example:"北京市海淀区培星小学"`
}

type AllScoreInfo struct {
	TotalScore           float32         `json:"total_score" example:"71.75"`
	EachItemScores       []ItemScoreInfo `json:"each_item_scores"`   //基本测试结果信息，柱状图仅展示基本测试结果信息
	ExpandItemScores     []ItemScoreInfo `json:"expand_item_scores"` //拓展测试成绩信息
	ClassStudentNum      int             `json:"class_student_num" example:"56"`
	ClassRank            int             `json:"class_rank" example:"22"`          //排名，百分比需要客户端计算，下同
	BlockStudentNum      int             `json:"block_student_num" example:"1689"` //区学生数量
	BlockRank            int             `json:"block_rank" example:"720"`
	CityStudentNum       int             `json:"city_student_num" example:"13222"` //全市学生数量
	CityRank             int             `json:"city_rank" example:"4000"`
	BmiLevel             int             `json:"bmi_level" example:"1"` //0：偏瘦 1：标准 2：偏旁 3：肥胖
	BmiComment           []string        `json:"bmi_comment" example:"按照身高体重BMI评价方法你的体型属于偏瘦型,评论2,评论3,评论4"`
	BmiAnalyze           []string        `json:"bmi_analyze" example:"分析1,分析2,分析3,分析4"`     //index 对应各个类型分析,使用配置文件配置即可
	BmiScoreChange       []YearScore     `json:"bmi_score_change"`                          //BMI变化趋势
	PhysicalFunctionItem int             `json:"physical_function_score" example:"5"`       //身体机能每项对应EachItemScores中的Index，特指肺活量
	PhysicalQualityItem  []int           `json:"physical_quality_item" example:"0,1,2,3,4"` //身体素质每项对应EachItemScores中的Index
}

type ItemScoreInfo struct {
	ItemName      string  `json:"item_name" example:"1分钟跳绳"`
	ItemLabel     string  `json:"item_label" example:"协调"` //对应身体机能、速度、柔韧、耐力、力量、灵敏
	ItemScore     float32 `json:"item_score" example:"78.9"`
	UpgradeInfo   string  `json:"upgrade_info" example:"说明速度素质较差。可能有几个原因所致：跑步技术不对、腿部力量不足、跑步姿势不正确，上下肢配合不协调等。正确的练习和长期的坚持，可有效提高50米跑步的成绩。"`
	SchemeLabelId int     `json:"scheme_label_id" example:"1"` //对应提升方案的标签Id
}

type YearScore struct {
	TestTime string  `json:"test_time" example:"2017-01-01"`
	Score    float32 `json:"score" example:"65.3"`
}

func (u *UserInfo) Validate() (ok bool) {
	if !govalidator.StringLength(u.PicUrl, "1", "255") {
		return
	}
	if !govalidator.StringLength(u.NickName, "1", "255") {
		return
	}
	if u.Gender != "男" && u.Gender != "女" {
		return
	}
	_, err := time.Parse("2006-01-02", u.Birth)
	if err != nil {
		return
	}
	ok = true
	return
}

type WechatAuthCode struct {
	OpenId     string `json:"openid"`
	SessionKey string `json:"sessionKey"`
	UnionId    string `json:"unionid"`
	ErrCode    int    `json:"errcode"`
	ErrMsg     string `json:"errmsg"`
}

type AvatarList struct {
	AvatarList []AvatarListInfo `json:"avatar_list"`
}

type AvatarListInfo struct {
	Id     int64  `json:"id" example:"1"`
	PicUrl string `json:"pic_url" example:"https://test-jingshi-pic.oss-cn-beijing.aliyuncs.com/avatar/defalut-male.png"`
}
